package d1m;

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.WirelessContentCheckRequest;
import com.taobao.api.request.WirelessPictureCheckRequest;
import com.taobao.api.response.WirelessContentCheckResponse;
import com.taobao.api.response.WirelessPictureCheckResponse;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * @Description:
 * @Author: Jason.zhu
 * @Create: 2019/11/26 14:46
 */

public class Client {
    private static String APP_KEY = "26022112";

    private static String APP_SECRET = "e502920c077ec8119860f1ef4f75cf86";

    public static void main(String[] args) throws Exception{
        /*String file = "D:\\myGit\\javaCode\\openTaobao\\sources\\imagesList.txt";
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))){
            String taobaoUrl = "http://gw.api.taobao.com/router/rest";
            String url = br.readLine();
            while (null != url && url.trim().length() > 0) {
                TaobaoClient client = new DefaultTaobaoClient(taobaoUrl, APP_KEY, APP_SECRET);
                WirelessPictureCheckRequest req = new WirelessPictureCheckRequest();
                req.setUrl(url);
                WirelessPictureCheckResponse rsp = client.execute(req);
                String result = url + "\t" + rsp.getSuggestion();
                System.out.println(result);
                url = br.readLine();
            }
        }finally {
            System.out.println("end !!");
        }*/
        checkText();
    }

    public static void checkText() throws Exception{
        String url = "http://gw.api.taobao.com/router/rest";
        TaobaoClient client = new DefaultTaobaoClient(url, APP_KEY, APP_SECRET);
        WirelessContentCheckRequest req = new WirelessContentCheckRequest();
        req.setText("娇兰高级定制");
        WirelessContentCheckResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
        System.out.println(rsp.getSuggestion());
    }

    public static void checkImageFile() throws Exception{
        String file = "D:\\myGit\\javaCode\\openTaobao\\sources\\imagesList.txt";
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))){
            String taobaoUrl = "http://gw.api.taobao.com/router/rest";
            String url = br.readLine();
            while (null != url && url.trim().length() > 0) {
                TaobaoClient client = new DefaultTaobaoClient(taobaoUrl, APP_KEY, APP_SECRET);
                WirelessPictureCheckRequest req = new WirelessPictureCheckRequest();
                req.setUrl(url);
                WirelessPictureCheckResponse rsp = client.execute(req);
                String result = url + "\t" + rsp.getSuggestion();
                System.out.println(result);
                url = br.readLine();
            }
        }finally {
            System.out.println("end !!");
        }
    }


}
